﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum props
{
    // 障碍物
    trap,
    // 不受控制的旋转
    messRotate,
    // 增加步数
    addStep,
    // 增加金币
    addMoney
}

public class RandomPropController : MonoBehaviour {

    /// <summary>
    /// 魔方的6个中心面
    /// </summary>
    public GameObject upCenter;
    public GameObject downCenter;
    public GameObject rightCenter;
    public GameObject leftCenter;
    public GameObject frontCenter;
    public GameObject backCenter;

    // 通关道具预制体
    public GameObject endPropPre;
    // 所有平面数组
    [HideInInspector]
    public GameObject[] MoFang;
    // 没有颜色数组
    [HideInInspector]
    public ArrayList noColorPanel;
    // 中心面数组
    [HideInInspector]
    public GameObject[] centerArr;
    // 统计没有颜色的块的总数
    int count = 0;

    void OnEnable()
    {
        MoFang = GameObject.FindGameObjectsWithTag("panel");
        noColorPanel = new ArrayList(MoFang);
        centerArr = new GameObject[6] { upCenter, downCenter, rightCenter, leftCenter, frontCenter, backCenter };
    }

    void Start()
    {

    }
    
    /// <summary>
    /// 调用此函数会返回一个随机道具
    /// </summary>
    /// <param name="index">随机数 范围0~3</param>
    /// <returns></returns>
    public props RandomPropEnum(int index)
    {
        // 定义一个变量 接收随机到的道具
        props prop = new props();
        switch (index)
        {
            case 0:
                {
                    prop = props.addMoney;
                    break;
                }
            case 1:
                {
                    prop = props.messRotate;
                    break;
                }
            case 2:
                {
                    prop = props.addStep;
                    break;
                }
            case 3:
                {
                    prop = props.trap;
                    break;
                }
            default:
                break;
        }

        return prop;
    }
    
    public void RemovePanel(GameObject gameObj)
    {
        Debug.Log("gameObj = " + gameObj);
        noColorPanel.Remove(gameObj);
    }

    /// <summary>
    /// 随机一个没有颜色的面生成道具
    /// </summary>
    public void RandomPropOnCube()
    {
        int index = Random.Range(0, noColorPanel.Count);
        Debug.Log(noColorPanel[index]);
        GameObject panel = noColorPanel[index] as GameObject;
        Transform endPanel = panel.transform.FindChild("point");
        GameObject end = Instantiate(endPropPre, endPanel.position, Quaternion.identity);
        end.transform.SetParent(endPanel);
    }

}
